<?php
$terms = isset($_['terms']) ? $_['terms'] : array();
$sources = isset($terms['source']) ? $terms['source'] : array();
$last_sync_result = isset($_['last_sync_result']) ? $_['last_sync_result'] : array();
$o_list = isset($_['offsite_list']) ? $_['offsite_list'] : array();
if (in_array($_['tab'], $sources)) {
   $default_source = $_['tab'];
} else {
   $default_source = isset($sources[0]) ? $sources[0] : '';
}

?>

<?php foreach ($sources as $k => $source): ?>
<?php if($source != 'pipapai'): ?>
<?php

$syncing_status = !empty($last_sync_result[$source]['result']) ? $last_sync_result[$source]['result'] : 'syncing';
$totalpages = !empty($last_sync_result[$source]['totalpages']) ? $last_sync_result[$source]['totalpages'] : 0;
$totalrecords = !empty($last_sync_result[$source]['totalrecords']) ? $last_sync_result[$source]['totalrecords'] : 0;
$nowpage = !empty($last_sync_result[$source]['nowpage']) ? $last_sync_result[$source]['nowpage'] : 1;
$numitems = 0; 

// Clear hidden_resume every time
$hidden_resumes = 0;

switch ($source) {
   case '51job':
      $sourcefrom = "前程无忧";
      break;
   case 'zhilian':
      $sourcefrom = "智联招聘";
      break;
   case 'jiancai':
      $sourcefrom = "建筑英才";
      break;
   default:
      $sourcefrom = "第三方网站";
      break;
}
?>
<table class="resume_listtable medium <?=$source?>" data-source="<?=$source?>" data-delaytaskid="<?php echo isset($last_sync_result[$source]['delaytaskid']) ? intval($last_sync_result[$source]['delaytaskid']) : 0;?>" style="<?php echo $default_source==$source ? "" : "display:none;";?>border-collapse:separate;" width="100%" cellspacing="0" cellpadding="0" border="0">
   <thead>
      <tr>
         <th align="left" style="padding-left:10px;" class="headresumeName <?=$source?>">
            <input type="checkbox" class="offsite_select_all <?=$source?>" data-type="<?=$source?>" style="margin-right:0px;"/>
            <em style="margin-right:20px; font-weight:normal;">全选</em>
            <span class="name">简历名称</span>
            <span class="actions_change">
               <span class="selectedAction hide <?=$source?>">
                  <a class="import" data-source="<?=$source?>" href="javascript:;" title="导入公司云人才库"> <i class="import"></i> 批量导入 </a>
               </span>
               <span class="selectedAction hide <?=$source?>">
                  <a class="sethide" data-source="<?=$source?>" href="javascript:;" title="下次不再显示"> <i class="sethide"></i> 批量隐藏 </a>
               </span>
               <span class="selectedAction hide <?=$source?>">
                  <a class="sethided" data-source="<?=$source?>" href="javascript:;"> <i class="sethided"></i> 取消隐藏 </a>
               </span>

               <span class="selectedAction hide" style="font-weight:normal; margin-left:20px;">下载剩余：<em style="color:#ff6000;"><?php echo isset($last_sync_result[$source]['downnumber']) ? intval($last_sync_result[$source]['downnumber']) : 0;?></em>份</span>
            </span>
         </th>
         <th align="left" id=""><span>工作经验</span></th>
         <th align="left" id=""><span>学历</span></th>
         <th align="left" id=""><span>职能</span></th>
         <th align="center" id=""><span>年龄</span></th>
         <th align="left" id=""><span>现居住地</span></th>
         <th align="left" id=""><span>期望月薪</span></th>
         <th align="center" id="updateTime" class="selected"><span><a href="javascript:;" class="" style="cursor:default;">简历更新时间<i class="downblack desc"></i></a></span></th>
      </tr>
   </thead>

   <tbody id="resumeList" class="<?=$source?>">
   <?php if ($syncing_status =='success'): ?>
      <?php if ($totalrecords > 0): ?>
      <?php foreach ($o_list as $key => $resume): ?>
         <?php if ($resume['source'] == $source): ?>
         <?php $numitems++; ?>
         <tr <?php echo ($key % 2 == 0) ? '' : 'bgcolor="#f5f7f8"';?> class="control_trselect tdnoborder_bottom <?php echo $resume['is_viewed'] ? '': 'bold';echo $resume['is_show'] == 1 ? ' selectable' : ' hiddenresume';echo $_['showsearchresumedetails'] == 1 ? ' tr_hovercolor' : '';?>" data-resumeid="<?=$resume['id']?>" data-resumecode="<?=$resume['resume_code']?>" data-source="<?=$source?>" style="<?php echo $resume['is_show'] == 1 ? '' : 'display:none;';?>">
            <td width="230" class="resumetitle <?=$source?>">
               <div style="padding:0 88px 0 60px;" class="clearfix">
                  <input type="checkbox" data-type="<?=$source?>" class="<?=$source?> osp_input">

                  <?php
                  if ($resume['is_show'] == 1) {
                     echo '<a href="javascript:;" class="actions sethide dohide" title="隐藏(下次不再显示)"></a>';
                  } else {
                     $hidden_resumes++;
                     echo '<a href="javascript:;" class="actions sethide sethided" title="取消隐藏"></a>';
                  }

                  if ($resume['is_imported'] == 1) {
                     echo '<a href="javascript:;" class="actions import imported" title="已导入"></a>';
                  } else {
                     echo '<a href="javascript:;" class="actions import" title="导入"></a>';
                  }
                  ?>

                  <a href="<?=$_['viewURL'].$resume['id']?>" target="_blank" class="name" data-resumeid="<?=$resume['resume_code']?>">
                     <span style="min-width:50px;" class="nametext"><?php echo $resume['keywords'] ? $resume['keywords'] : '无名称简历';?></span>
                  </a>
                  <span class="clearfix">
                     <span class="<?php echo $resume['sex']=='F' ? 'wresumepng' : 'mresumepng';?>"></span>
                     <?php if($resume['is_saved'] == 1): ?>
                     <span class="isfolder" title="该简历已在您<?=$sourcefrom?>的公司人才夹"></span>
                     <?php endif;?>
                     <?php if($resume['is_new'] == 1): ?>
                     <span class="isnew"></span>
                     <?php endif;?>
                  </span>
                  <span class="clicktoggle"></span>
               </div>
            </td>
            <td width="80"> <?=$resume['workexp']?> </td>
            <td width="60"> <?=$resume['degree_level']?> </td>
            <td width="140"> <?=$resume['job_spec']?> </td>
            <td width="50" align="center"> <?=$resume['age']?> </td>
            <td width="90"> <?=$resume['city'].' '.$resume['citydist']?> </td>
            <td width="100"> <?php echo (empty($resume['expect_salary']) || $resume['expect_salary'] == '面议') ? '面议' : $resume['expect_salary'].'元/月'?> </td>
            <td width="90" align="center"><span class="modified"> <?=$resume['update_time']?> </span></td>
         </tr>
         <tr class="control_tr" style="<?php echo $resume['is_show'] == 1 ? '' : 'display:none;';?>">
            <td colspan="8" class="resume_detailtd" width="100%">
               <div class="relative">
                  <div class="resumedetails clearfix" <?php if(empty($_['showsearchresumedetails'])): ?>style="display:none;" <?php endif; ?>>
                     <div class="putavatorimg pull-left">
                        <img src="<?php echo !empty($resume['avatar']) ? $resume['avatar'] : '/images/jobseeker_90x110.jpg';?>"/>
                     </div>
                     <div style="padding-top:10px; margin-left:121px;" class="clearfix">
                        <?php if(!empty($resume['highest_edu'])):?>
                        <div class="resumejob"><b>院校专业：</b><span><?=$resume['highest_edu']?></span></div>
                        <?php endif;?>
                        <?php if(!empty($resume['last_work'])):?>
                        <div class="resumejob"><b>最近工作：</b><span><?=$resume['last_work']?></span></div>
                        <?php endif;?>
                        <?php if(!empty($resume['job_status'])):?>
                        <div class="resumejob"><b>求职状态：</b><span><?=$resume['job_status']?></span></div>
                        <?php endif;?>
                        <?php if(!empty($resume['now_salary'])):?>
                        <div class="resumejob"><b>目前薪资：</b><span><?php echo $resume['now_salary'].'元/月'?></span></div>
                        <?php endif;?>
                        <?php if(!empty($resume['history_work'])):?>
                        <div class="resumejob"><b>工作经历：</b><span><?php echo nl2br($resume['history_work']);?></span></div>
                        <?php endif;?>
                        <?php if(!empty($resume['summary'])):?>
                        <div class="resumejob"><b>个人总结：</b><span><?php echo nl2br($resume['summary']);?></span></div>
                        <?php endif;?>
                     </div>
                     <div class="resume_hrtaget"> </div>
                  </div>
                  <!-- <div class="clicktoggle" title="点击查看详情" data-delay="1"></div> --> 
               </div>
            </td>
         </tr>
         <?php endif;?>
      <?php endforeach;?>

      <tr class="yellowtrline <?=$source?>" style="<?php echo $hidden_resumes>0 ? '' : 'display:none;'?>">
         <td colspan=8 align="center">
            <b>本页已隐藏简历<?=$hidden_resumes?>份</b>
            <button class="ppp_whitebtn expand_hidden" data-source="<?=$source?>" data-stats="hidden">展开</button>
         </td>
      </tr>

      <?php endif; ?>

      <?php if($numitems <= 0) : ?>
      <tr><td colspan=8>没有找到符合条件的简历</td></tr>
      <?php endif;?>
   <?php else: ?>
   <tr class="checking">
      <td colspan=8>
         <?php if($nowpage > 1) : ?>
            正在努力加载中...&nbsp;&nbsp;
         <?php else: ?>
            正在搜索简历...&nbsp;&nbsp;
         <?php endif; ?>
         <span class="status"></span>
      </td>
   </tr>
   <?php endif;?>
   </tbody>
   <?php
   ?>
   <?php if ($syncing_status == 'success' && $totalpages > 1 && $numitems > 0) : ?>
   <tfoot>
      <tr>
         <td colspan="8">
            <div class="list-footer">
               <div class="pagination pagination-small pagination-centered offsitepagination">
                  <ul data-type="<?=$source?>">
                     <?php
                        $max = $nowpage < 9 ? ($totalpages <= 10 ? 10 : 9)  :($totalpages - $nowpage <= 5 ? ($nowpage+(10-($totalpages-$nowpage))) : $nowpage+4) ;
                        $start = $nowpage < 9 ? 1 : ($totalpages-$nowpage<4 ? ($nowpage-(9-($totalpages-$nowpage))):$nowpage-4);
                        if ($nowpage == 1) {
                           echo '<li class="active disabled"><span>上页</span></li>';
                        } else {
                           echo '<li data-page="'.($nowpage-1).'" class=""><a href="javascript:;">上页</a></li>';
                           if($start > 1){
                              echo '<li data-page="1" class=""><a href="javascript:;">1...</a></li>';
                           }
                        }

                        for ($i=$start; $i <= $max; $i++) {
                           $active = $nowpage == $i ? 'active' : '';
                           if ($i <= $totalpages) {
                              if ($active) {
                                 echo '<li class="'.$active.'"><span>'.$i.'</span></li>';
                              } else {
                                 echo '<li data-page="'.$i.'" class=""><a href="javascript:;">'.$i.'</a></li>';
                              }
                           }
                           $active = '';
                        }
                        if ($nowpage >= $totalpages) {
                           echo '<li class="active disabled"><span>下页</span></li>';
                        } else {
                           if($totalpages - $nowpage <= 5 || $totalpages <= 10){
                              echo '<li data-page="'.($nowpage+1).'"><a href="javascript:;">下页</a></li>';
                           }else{
                              echo '<li data-page="'.$totalpages.'"><a href="javascript:;">...'.$totalpages.'</a></li>';
                              echo '<li data-page="'.($nowpage+1).'"><a href="javascript:;">下页</a></li>';
                           }
                        }
                     ?>
                  </ul>
               </div>
            </div>
         </td>
      </tr>
   </tfoot>
   <?php endif;?>
</table>

<div class="modal hide fade import_confirm <?=$source;?>" data-source="<?=$source?>" aria-hidden="false">
   <div class="modal-header">
      <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
      <h3>&nbsp;</h3>
   </div>
   <div class="modal-body">
      <div class="confirmtext import hide">导入简历将扣除您在<?php echo $sourcefrom;?>的<b>1个下载数</b>，是否确认？</div>
      <div class="confirmtext imported hide">重新导入将不再扣除<?php echo $sourcefrom;?>下载数，是否<b>重新导入</b>？</div>
      <button class="ppp_bluebtn">确定</button>
   </div>
</div>

<?php endif;?>
<?php endforeach;?>
